package thread;

import java.util.concurrent.Semaphore;

/**
 * Creared with IntelliJ IDEA.
 * Description:
 * User:yxd
 * Date:2022-04-02
 * Time:21:26
 */
public class Demo30 {
    public static void main(String[] args) throws InterruptedException {
        //初始化的值表示可用资源有4个
        Semaphore semaphore = new Semaphore(4);
        //申请资源,P操作
        semaphore.acquire();//还可用申请或释放多个资源加参数,当资源申请完了再次申请的话就会曹成阻塞效果,释放也是一样的
        //释放资源,V操作
        semaphore.release();
    }
}
